package drive.Mapper;

import drive.Model.ReportRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReportRecordMapper {
    // 查询所有举报记录
    @Select("SELECT * FROM reportrecord WHERE reportStatus != 'handled'")
    List<ReportRecord> findAll();

    // 根据reportID查询举报记录
    @Select("SELECT * FROM reportrecord WHERE reportID = #{reportID}")
    ReportRecord findByReportID(int reportID);

    // 根据reporterID和reporteeID查询举报记录
    @Select("SELECT * FROM reportrecord WHERE reporterID = #{reporterID} AND reporteeID = #{reporteeID}")
    ReportRecord findByReporterAndReportee(int reporterID, int reporteeID);

    // 新增举报记录
    @Insert("INSERT INTO reportrecord (reporterID, reporteeID, reportType, reportReason, handlingResult, submissionTime, handlingTime, reportStatus) VALUES (#{reporterID}, #{reporteeID}, #{reportType}, #{reportReason}, #{handlingResult}, #{submissionTime}, #{handlingTime}, #{reportStatus})")
    int add(ReportRecord reportRecord);

    // 更新举报记录
    @Update("UPDATE reportrecord SET reporterID = #{reporterID}, reporteeID = #{reporteeID}, reportType = #{reportType}, reportReason = #{reportReason}, handlingResult = #{handlingResult}, submissionTime = #{submissionTime}, handlingTime = #{handlingTime}, reportStatus = #{reportStatus} WHERE reportID = #{reportID}")
    int update(ReportRecord reportRecord);

    // 删除举报记录
    @Delete("DELETE FROM reportrecord WHERE reportID = #{reportID}")
    int delete(int reportID);

    /**
     * 获取所有未处理的举报
     * @return 举报记录列表
     */
    @Select("SELECT * FROM reportrecord WHERE reportStatus = 'pending'")
    List<ReportRecord> getPendingReports();
}
